package com.louis.affair.xmltx.service.impl;

import com.louis.affair.xmltx.dao.BookDao;
import com.louis.affair.xmltx.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author XRY
 * @date 2023年06月28日9:53
 */
@Service
public class BookServiceImpl implements BookService {

    @Autowired
    private BookDao bookDao;

    @Override
    public void buyBook(Integer bookId, Integer userId) {
        //根据图书id查询图书价格
        Integer price = bookDao.selectBookById(bookId);
        //更新图书库存
        bookDao.updateBookById(bookId);
        //更新用户表余额
        bookDao.updateUserBalance(userId, price);
    }
}
